package com.xin.di.uav.applet.rest;

import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.xin.di.uav.applet.service.ICommodityService;
import com.xin.di.uav.common.request.operate.CommodityReq;
import com.xin.di.uav.common.response.operational.CommodityRes;
import com.xin.di.uav.common.utils.RespJsonPageData;
import com.xin.di.uav.common.utils.Rs;
import com.xin.di.uav.user.order.po.Product;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.RestController;

import java.util.List;
import java.util.Set;

/**
 * <p>
 * 前端控制器
 * </p>
 *
 * @author LTQ
 * @since 2023-12-07
 */
@RestController
public class CommodityRest {

    @Autowired
    private ICommodityService iCommodityService;

    public List<Product> getByBusinessId(String businessId) {
        return iCommodityService.getByBusinessId(businessId);
    }


    public Product getById(String id) {
        return iCommodityService.getById(id);
    }

    public List<Product> selectProductByBusinessIds(Set<String> ids){
        return iCommodityService.list(new QueryWrapper<Product>().in("business_id",ids));
    }

    public RespJsonPageData<CommodityRes> getPageCommodity(CommodityReq commodityReq) {
        return iCommodityService.getPageCommodity(commodityReq);
    }

    public Rs<Integer> addCommodity(CommodityReq commodityReq) {
        return iCommodityService.save(commodityReq);
    }
    public Rs<Integer> editCommodity(CommodityReq commodityReq) {
        return iCommodityService.updateById(commodityReq);
    }

    public List<Product> selectProductByIds(Set<String> ids){
        return iCommodityService.listByIds(ids);
    }

    public boolean updateCommodityById(List<Product> commodityList){
        return iCommodityService.updateBatchById(commodityList);
    }
}
